package br.ufpb.di.knowledgetv.persistencia;

import java.util.List;

import javax.jdo.PersistenceManager;

import br.ufpb.di.knowledgetv.instancias.Perfil;
import br.ufpb.di.knowledgetv.instancias.Perfil;

public class GerenciadorDeDados {
	
	public static void persistir(Perfil u){
		PersistenceManager pm = PMF.get().getPersistenceManager();
		pm.makePersistent(u);
		pm.close();
	}
	
	@SuppressWarnings("unchecked")
	public static List<Perfil> listar(){
		PersistenceManager pm = PMF.get().getPersistenceManager();
		String query = "select from " + Perfil.class.getName();
		List<Perfil> list =  (List<Perfil>) pm.newQuery(query).execute();
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public static void limpar(){
		PersistenceManager pm = PMF.get().getPersistenceManager();
		List<Perfil> list = (List<Perfil>) pm.newQuery("select from " + Perfil.class.getName()).execute();
		for( Perfil u : list )
			pm.deletePersistent(u);
		pm.close();
	}

}
